#include #include using namespace std; int stringLength(char s[]) { int result = 0; while(s[result] != '\0') { result++; } return result; } int stringCompare(char s1[], char s2[]) { int result = 0; int i = 0; while(s1[i] != '\0' && s2[i] != '\0' && result == 0) { if(s1[i] < s2[i]) { result = -1; } else if (s1[i] > s2[i]) { result = 1; } i++; } if(result == 0 && s1[i] != '\0') { result = 1; } else if(result == 0 && s2[i] != '\0') { result = -1; } return result; } void main() { int A[] = {1,23,44,66,77}; cout << A << endl; char A1[] = {'a','b','c','d'}; cout << A1 << endl; char A2[] = {'a','b','c','d', '\0'}; cout << A2 << endl; //c-style strings //char array with a null terminator // \0 - escape sequence for the null terminator char A3[9] = {'a','b','c','d'}; cout << A3 << endl; char A4[] = {65,'b','c','d',0}; cout << A4 << endl; char A5[] = "abcd"; cout << A5 << endl; //char A6[100]; //cin >> A6; //cout << A6 << endl; //char A7[5]; //A7[4] = 'a'; //cin >> A7; //cout << A7 << endl; char A8[100]; cin.getline(A8,100); cout << A8 << endl; cout << stringLength(A8) << endl; //if(A8 == "Apple") //{ // cout << "It is an apple" << endl; //} if(stringCompare(A8,"Apple") == 0) { cout << "It is an apple" << endl; } cout << stringCompare(A8,"Apple") << endl; }